package com.jjb.www.ui.dialog;

import android.content.Context;
import android.text.Html;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.hjq.base.BaseDialog;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.aop.SingleClick;

import java.util.List;


/**
 * author : Android
 * time   : 2019/03/20
 * desc   : 规则Dialog
 */
public final class RuleDialog {

    public static final class Builder
            extends BaseDialog.Builder<Builder> {
        @Nullable
        private OnListener mListener;
        private ShapeImageView mImgFish;
        private AppCompatTextView mTvHint;
        private ShapeTextView mTv1;
        private ShapeTextView mTv2;
        private ShapeTextView mTv3;
        private ShapeTextView mTv4;
        private ShapeTextView mTv5;
        private ShapeTextView mTv6;
        private ShapeTextView mTv7;
        private ShapeTextView mTv8;
        private ShapeTextView mTv9;
        private ShapeTextView mTv10;
        private ShapeTextView mTv11;
        private ShapeTextView mTv12;
        private ShapeTextView mTvAuthorization;

        public Builder(Context context) {
            super(context);
            setContentView(R.layout.rule_dialog);
            setAnimStyle(BaseDialog.ANIM_BOTTOM);
            setCancelable(true);
            mImgFish = findViewById(R.id.img_fish);
            mTvHint = findViewById(R.id.tv_hint);
            mTv1 = findViewById(R.id.tv_1);
            mTv2 = findViewById(R.id.tv_2);
            mTv3 = findViewById(R.id.tv_3);
            mTv4 = findViewById(R.id.tv_4);
            mTv5 = findViewById(R.id.tv_5);
            mTv6 = findViewById(R.id.tv_6);
            mTv7 = findViewById(R.id.tv_7);
            mTv8 = findViewById(R.id.tv_8);
            mTv9 = findViewById(R.id.tv_9);
            mTv10 = findViewById(R.id.tv_10);
            mTv11 = findViewById(R.id.tv_11);
            mTv12 = findViewById(R.id.tv_12);
            mTvAuthorization = findViewById(R.id.tv_authorization);
            setOnClickListener(mTvAuthorization, mImgFish);
        }

        public Builder setListener(OnListener listener) {
            mListener = listener;
            return this;
        }

        public Builder setTitle(String title) {
            mTvHint.setText(Html.fromHtml(title));
            return this;
        }
        public Builder settable_th(List<String> th) {
            mTv1.setText(Html.fromHtml(th.get(0)));
            mTv2.setText(Html.fromHtml(th.get(1)));
            mTv3.setText(Html.fromHtml(th.get(2)));
            return this;
        }

        public Builder settable_td1(List<String> th) {
            mTv4.setText(Html.fromHtml(th.get(0)));
            mTv5.setText(Html.fromHtml(th.get(1)));
            mTv6.setText(Html.fromHtml(th.get(2)));
            return this;
        }
        public Builder settable_td2(List<String> th) {
            mTv7.setText(Html.fromHtml(th.get(0)));
            mTv8.setText(Html.fromHtml(th.get(1)));
            mTv9.setText(Html.fromHtml(th.get(2)));
            return this;
        }
        public Builder settable_td3(List<String> th) {
            mTv10.setText(Html.fromHtml(th.get(0)));
            mTv11.setText(Html.fromHtml(th.get(1)));
            mTv12.setText(Html.fromHtml(th.get(0)));
            return this;
        }

        /**
         * 设置提示
         */
        public Builder setHint(CharSequence hint) {
            return this;
        }

        @SingleClick
        @Override
        public void onClick(View view) {
            if (view == mTvAuthorization) {
                if (mListener == null) {
                    return;
                }
                dismiss();
                mListener.onCompleted(getDialog());
            } else if (view == mImgFish) {
                if (mListener == null) {
                    return;
                }

                dismiss();
                mListener.onCancel(getDialog());
            }
        }
    }
    public interface OnListener {
        void onCompleted(BaseDialog dialog);
        void onCancel(BaseDialog dialog);
    }
}